cmake_minimum_required(VERSION 3.11)
project(formatpanel LANGUAGES CXX)

# 设置项目版本
set(PROJECT_VERSION 1.0.0)

# 启用自动处理 Qt 元对象系统
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

# 设置 C++17 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 定义动态库导出宏
add_definitions(-DFORMATPANEL_LIBRARY)

# 查找 Qt 组件
find_package(Qt5 REQUIRED COMPONENTS Core Widgets )

# 设置包含目录
include_directories(
    include
    ${Qt5Core_INCLUDE_DIRS}
    ${Qt5Widgets_INCLUDE_DIRS}
)

# 源文件列表
set(SOURCES
	formatpanel.cpp
    iformatpanel.cpp
)

# 头文件列表
set(HEADERS
	formatpanel.h
	formatpanelglobal.h
	iformatpanel.h
)


qt5_create_translation(QM_FILES 
    ${SOURCES} ${HEADERS}  # 修复：使用已定义的 SOURCES 和 HEADERS 变量
)

# 创建动态库
add_library(formatpanel SHARED
    ${SOURCES}
    ${HEADERS}
)


# 链接 Qt 库
target_link_libraries(formatpanel PRIVATE
    Qt5::Core
    Qt5::Widgets
)




# 设置目标属性
set_target_properties(formatpanel PROPERTIES
    VERSION ${PROJECT_VERSION}
    SOVERSION 1
    OUTPUT_NAME "formatpanel"
    PUBLIC_HEADER "${HEADERS}"
)

# 安装规则
install(TARGETS formatpanel
    EXPORT formatpanelTargets
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin
    PUBLIC_HEADER DESTINATION include/formatpanel
)

install(EXPORT formatpanelTargets
    FILE formatpanelTargets.cmake
    NAMESPACE formatpanel::
    DESTINATION lib/cmake/formatpanel
)

# 设置库的输出目录
set_target_properties(${PROJECT_NAME} PROPERTIES
    OUTPUT_NAME "formatpanel"
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin  #.lib .exp 输出路径
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin  #.dll 输出路径
)